﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace MT_ToolKit
{
    public class VideoManager : MonoSingleton<VideoManager>
    {
        private Dictionary<string, VideoItem> videoItems = new Dictionary<string, VideoItem>();

        public VideoItem InitVideoItem(string videoName)
        {
            if (videoItems.ContainsKey(videoName))
                return videoItems[videoName];
            GameObject go = new GameObject(videoName);
            go.transform.SetParent(transform);
            VideoItem videoItem = go.AddComponent<VideoItem>();
            videoItems.Add(videoName, videoItem);
            return videoItem;
        }

        public VideoItem FindVideoItem(string videoName)
        {
            if (videoItems.ContainsKey(videoName))
                return videoItems[videoName];
            return null;
        }

        public void DeleteVideoItem(string videoName)
        {
            if (videoItems.ContainsKey(videoName))
            {
                videoItems[videoName].Stop();
                Destroy(videoItems[videoName].gameObject);
                videoItems.Remove(videoName);
            }
        }
    }
}